﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autofac;
using ComputerVision.Data;
using ComputerVision.Services;

namespace ComputerVision.UserControls
{
    public partial class ucBaoCaoTongHop : UserControl
    {
        private IService<Xe> _xe;
        private int type = 0;
        public ucBaoCaoTongHop()
        {
            InitializeComponent();
            _xe = Program.Container.Resolve<IService<Xe>>();
        }

        private void btTimkiem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            switch (type)
            {
                case 0:
                    var items =
                    _xe.ToList()
                       .Where(
                           p =>
                           p.NgayVao != null && p.NgayVao.Value.Date == DateTime.Now.Date);
                    lbKetQua.Text = items.Count().ToString();
                    xeBindingSource.DataSource = items.OrderByDescending(p => p.NgayVao);
                    break;
                case 1:
                    var items2 =
                    _xe.ToList()
                       .Where(
                           p =>
                           p.NgayVao != null && p.NgayVao.Value.Date >= DateTime.Today.AddDays(-7) &&
                       p.NgayVao.Value.Date <= DateTime.Today);
                    lbKetQua.Text = items2.Count().ToString();
                    xeBindingSource.DataSource = items2.OrderByDescending(p => p.NgayVao);
                    break;
                case 2:
                    var items3 =
                    _xe.ToList()
                       .Where(
                           p =>
                           p.NgayVao != null && p.NgayVao.Value.Date >= dtRaTu.Value.Date &&
                       p.NgayVao.Value.Date <= dtRaDen.Value.Date);

                    lbKetQua.Text = items3.Count().ToString();
                    xeBindingSource.DataSource = items3.OrderByDescending(p => p.NgayVao);
                    break;
            }
            Cursor.Current = Cursors.Default;
        }

        private void rbTrongNgay_CheckedChanged(object sender, EventArgs e)
        {
            type = 0;
        }

        private void rbTrongTuan_CheckedChanged(object sender, EventArgs e)
        {
            type = 1;

        }

        private void rbThoiGianTu_CheckedChanged(object sender, EventArgs e)
        {
            type = 2;

        }
    }
}
